package at.bartinger.gameoflive.otherstuff;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TextView;
import at.bartinger.gameoflive.R;
import at.bartinger.gameoflive.R.id;
import at.bartinger.gameoflive.R.layout;


public class SeekBarDialog extends Dialog implements SeekBar.OnSeekBarChangeListener{

	private SeekBar sb;
	private int prog;
	private OKListener l;
	private TextView text;
	private String title;
	
	public SeekBarDialog(Context context, String title,int max, int defprog, OKListener l) {
		super(context);
		setContentView(R.layout.slider); 
		setTitle(title); 
		
		this.prog = defprog;
		this.l = l;
		this.title = title;
		
		sb = (SeekBar) findViewById(R.id.sb);
		sb.setOnSeekBarChangeListener(this);
		
		//sb.setProgress(prog);
		sb.setMax(max);
		
		Button ok = (Button) findViewById(R.id.seekok);
		ok.setOnClickListener(new OKListenerObj());
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		sb.setProgress(prog);
	}

	@Override
	public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
		prog = seekBar.getProgress();
		SeekBarDialog.this.setTitle(title+": "+prog);
	}

	@Override
	public void onStartTrackingTouch(SeekBar seekBar) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onStopTrackingTouch(SeekBar seekBar) {
		// TODO Auto-generated method stub
		
	}
	
	private class OKListenerObj implements android.view.View.OnClickListener { 

		@Override 
		public void onClick(View v) { 
			l.onOKpressed(prog);
			SeekBarDialog.this.dismiss(); 
		}

	}
	
	public interface OKListener { 
        public void onOKpressed(int progress); 
   } 

}
